﻿
package extremefx.remoting {
	import extremefx.remoting.RestRequest;

	import flash.net.ObjectEncoding;
	import flash.net.URLLoaderDataFormat;
	import flash.utils.ByteArray;

	/**
	 * @author Marcelo Volmaro
	 */
	public class AmfRestRequest extends RestRequest {
//		private static var _e:RemotingError = new RemotingError();
		
		public function AmfRestRequest(pEndPoint:String, pSingle:String, pList:String = null) {
			super(pEndPoint, pSingle, pList);
			_dataFormat = URLLoaderDataFormat.BINARY;
//			_e = null;
		}
		
		public function update(pId:String, pData:Object):void {
			var ba:ByteArray = new ByteArray();
			ba.writeObject(pData);
			_update(pId, ba);
		}
		
		public function insert(pData:Object):void {
			var ba:ByteArray = new ByteArray();
			ba.writeObject(pData);
			_insert(ba);
		}
		
		override protected function _process(pData:*):* {
			var ba:ByteArray = (pData as ByteArray);
			ba.objectEncoding = ObjectEncoding.AMF3;
			return ba == null ? null : ba.readObject();
		}
	}
}
